<?php

include '../include/config.php';

$target_path = $_POST['path'];
$rp = $_POST['rp'];
$mdir = $_POST['mdir'];
$test_id = $_POST['test_id'];
$date = date('Y-m-d');
$bid = $_POST['bid'];

$target_path = $target_path . basename($_FILES['uploadedfile']['name']);
if (move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    //$fn = basename($_FILES['uploadedfile']['name']);
    $fn = $bid.'_'.$test_id.'.png' ;
    rename($target_path, $_POST['path'].$fn);
    mysql_query("insert into baby_mother_tests (`Sr`,`bid`,`test_id`,`test_date`,`file`,`status`) values(NULL,'" . $bid . "','" . $test_id . "','" . $date . "','" . $fn . "',1)") or die(mysql_error());
    //echo "insert into baby_upload_files (`Sr`,`file_name`,`bid`,`mdir`,`attr`,`date`) values(NULL,`".$fn."`,`".$_COOKIE['bid']."`,`".$mdir."`,`".$attr."`,$date)";
    header("Location:$rp&s=y");
} else {
    echo "There was an error uploading the file, please try again!";
    header("Location:$rp&s=n");
}
?>
